﻿#include <stdlib.h>

#include <gl/glew.h>
#include "shaders.h"

void compileShader(GLuint id)
{
	GLint status;
	glCompileShader(id);
	glGetShaderiv(id, GL_COMPILE_STATUS, &status);
	if (!status)
	{
		GLint len;
		glGetShaderiv(id, GL_INFO_LOG_LENGTH, &len);
		char *message = (char *) malloc(len * sizeof(char));
		glGetShaderInfoLog(id, len, 0, message);
		//F_ERROR(message)
	}
}

GLuint createShader(GLenum type, const char *source)
{
	void *myFunction = glCreateShader;
	GLuint id = glCreateShader(type);
	if (id == 0)
	{
		//ERROR(GL_VERTEX_SHADER? "Could not create vertex shader": "Could not create frag shader");
	}
	glShaderSource(id, 1, &source, 0);
	compileShader(id);
	return id;
}

void linkProgram(GLuint id)
{
	GLint status;
	glLinkProgram(id);
	glGetProgramiv(id, GL_LINK_STATUS, &status);
	if (!status) 
	{
		GLint len;
		glGetProgramiv(id, GL_INFO_LOG_LENGTH, &len);
		char *message = (char*) malloc(len*sizeof(char));
		glGetProgramInfoLog(id, len, 0, message);
	}
}